<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 13-1-28
 * Time: 上午11:20
 * To change this template use File | Settings | File Templates.
 */
class Model_Cfg_EntityDetail extends Jwawa_BaseModel
{
    public static function findEntityDetailByEntityCodes($entityCodes){
        if(empty($entityCodes) || count($entityCodes) == 0){
            return array();
        }
        $inEntityCodeStr = "'" . implode("','", $entityCodes) . "'";

        $sql = "SELECT ced.id,
                    ced.entity_header_id,
                    ceh.entity_code,
                    ced.entity_field_name,
                    ced.entity_field_label
                FROM cfg_entity_headers ceh
                JOIN cfg_entity_details ced ON ced.entity_header_id = ceh.id
                WHERE ceh.entity_code IN ($inEntityCodeStr)
                  AND ced.is_deleted = 'N'";

        $stmt = self::createDefaultStmt(self::getDb(), $sql);
        $stmt->execute();
        $entityDetailList = $stmt->fetchAllObj();
        return $entityDetailList;
    }

    public static function findEntityDetailListByHeaderId($entityHeaderId){
        if(empty($entityHeaderId)){
            return array();
        }

        $sql = "SELECT ced.id,
                    ced.entity_header_id,
                    ced.entity_field_name,
                    ced.entity_field_label
                FROM cfg_entity_details ced
                WHERE ced.entity_header_id = :entity_header_id
                  AND ced.is_deleted = 'N'
                ORDER BY ced.entity_field_name ";

        $stmt = self::createDefaultStmt(self::getDb(), $sql);
        $stmt->bindValue('entity_header_id', $entityHeaderId);
        $stmt->execute();
        $entityDetailList = $stmt->fetchAllObj('Model_Cfg_EntityDetail');
        return $entityDetailList;
    }
}
